package com.anolesoft.yr.demo;

import java.io.Serializable;
import java.util.List;

/**
 * @author zhj
 * @date 2021/7/22 15:21
 */
public class PageResult<T> implements Serializable {
    private Integer pageSize;
    private Integer pageNo;
    private Integer totalCount;
    private Integer totalPage;
    private List<T> data;
    private List<T> da; // SJM_20221215

    public PageResult(List<T> data, Integer pageSize, Integer pageNo, Integer totalCount){
        this.data = data;
        this.pageSize = pageSize;
        this.pageNo = pageNo;
        this.totalCount = totalCount;
        this.totalPage = calcTotalPage(totalCount.intValue(),pageSize.intValue());
    }
    public PageResult(List<T> data, Integer pageSize, Integer pageNo, Integer totalCount,List<T> da){
        this.data = data;
        this.pageSize = pageSize;
        this.pageNo = pageNo;
        this.totalCount = totalCount;
        this.totalPage = calcTotalPage(totalCount.intValue(),pageSize.intValue());
        this.da = da;
    }
    public PageResult(){

    }
    private Integer calcTotalPage(int totalCount,int pageSize){
        int iTotalPage = 1;
        iTotalPage = totalCount  % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        return Integer.valueOf(iTotalPage);
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public List<T> getDa() {
        return da;
    }

    public void setDa(List<T> da) {
        this.da = da;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "PageResult{" +
                "pageSize=" + pageSize +
                ", pageNo=" + pageNo +
                ", totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", data=" + data +
                ", da=" + da +
                '}';
    }
}
